<?php
namespace jy_daijia;
defined('BY_JYA') or exit('error');
/*
	消息提醒
*/
class notice extends \plugin{
	public function add_msg($params){
		$data=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$params['mid']?:$_SESSION['uid'],
			'message'=>$params['message'],
		);
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_daijia_message',$data);
		$msgid=pdo_insertid();
		return $msgid;
	}
	public function notice_create2buyer($orderid,$url=''){
		$order=pdo_get('jy_daijia_order',array('id'=>$orderid));
		//发送订单生成通知给买方		
		$template_id=cfc('account')->get_tpl_template_id('OPENTM200746866','呼叫代驾成功通知');
		if($_SESSION['wxapp_id']){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('1290',[1,2,3,4],'create2buyer','新订单通知','jy_daijia');
		}
		$setting=$this->plugin_setting('setting');
		$message=array(
			'first'=>array('value'=>'呼叫代驾成功通知',"color" => "#4a5077"),
			'keyword1'=>array('value'=>'代驾',"color" => "#4a5077"),
			'keyword2'=>array('value'=>$order['start_seat'],"color" => "#4a5077"),
			'keyword3'=>array('value'=>$order['dest_seat'],"color" => "#4a5077"),
			'keyword4'=>array('value'=>price($order['price']),"color" => "#4a5077"),
			'remark'=>array('value'=>'谢谢惠顾！点击“详情”查看订单信息。',"color" => "#4a5077"),
		);
		$statustitle=$order['status']==1?'已下单':'待支付';
		$wxappmsg=array(
			array('value'=>'代驾'),
			array('value'=>$order['start_seat']),
			array('value'=>$order['dest_seat']),
			array('value'=>price($order['price'])),
		);
		if(!$url){
			$url=custom_url('jy_daijia/order/detail/id='.$order['id'],true);	
		}
		if(method_exists(cfc('account'),'sendtwoNotice')){
			cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'create2buyer','jy_daijia',$order['id']);
		}
		if($_SESSION['wxapp_id']){
			$template_id=cfc('wxapp_api')->checktplNotice($order['mid'],$wxapptemplate_id,$wxappmsg,$url,'create2buyer','jy_daijia',$order['id']);
		}
	}
	public function notice_get2user($orderid,$driverid){
		$order=pdo_get('jy_daijia_order',array('id'=>$orderid));
		$driver=pdo_get('jy_daijia_driver',array('id'=>$driverid));
		//发送订单取消通知给买方		
		$template_id=cfc('account')->get_tpl_template_id('TM00850','代驾司机接单通知');
		if($_SESSION['wxapp_id']){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('205',[1,2,3],'get2user','代驾司机接单通知','jy_daijia');
		}
		$msg1='师傅已经接了你的订单，预计20分钟后抵达';
		$message=array(
			'first'=>array('value'=>'代驾司机接单通知',"color" => "#4a5077"),
			'orderProductPrice'=>array('value'=>$order['price'],"color" => "#4a5077"),
			'orderProductName'=>array('value'=>$order['goods']['0']['title'],"color" => "#4a5077"),
			'orderAddress'=>array('value'=>$address_str,"color" => "#4a5077"),
			'orderName'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'remark'=>array('value'=>'点击“详情”查看详细处理信息，如有疑问可直接联系客服。',"color" => "#4a5077"),
		);
		$url=custom_url('jy_daijia/order/detail/id='.$order['id'],true);
		$wxappmsg=array(
			array('value'=>$msg1),
			array('value'=>$driver['name']),
			array('value'=>$driver['number']?:'DD'.$driver['id']),
		);
		if(method_exists(cfc('account'),'sendtwoNotice')){
			cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'get2user','jy_daijia',$order['id']);
		}
		if($_SESSION['wxapp_id']){
			$template_id=cfc('wxapp_api')->checktplNotice($order['mid'],$wxapptemplate_id,$wxappmsg,$url,'get2user','jy_daijia',$order['id']);
		}
	}
	public function notice_nopay2buyer($order,$url=''){
		$order=pdo_get('jy_daijia_order',array('id'=>$orderid));
		//发送订单支付通知给买方
		$template_id=cfc('account')->get_tpl_template_id('OPENTM204987032','订单待支付通知');	
		if($_SESSION['wxapp_id']){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('4968',[1,2,6,7,5],'nopay2buyer','订单支付成功通知','jy_daijia');
		}
		$message=array(
			'first'=>array('value'=>'订单待支付通知',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>$statustitle,"color" => "#4a5077"),
			'keyword3'=>array('value'=>date('Y/m/d H:i:s',$order['paytime']),"color" => "#4a5077"),
			'keyword4'=>array('value'=>$shopset['title'],"color" => "#4a5077"),
			'keyword5'=>array('value'=>$order['price'],"color" => "#4a5077"),
			'remark'=>array('value'=>'谢谢惠顾！欢迎您的再次到来！点击“详情”查看订单信息。',"color" => "#4a5077"),
		);
		$wxappmsg=array(
			array('value'=>$order['ordersn']),
			array('value'=>price($order['price'])),
			array('value'=>$order['start_seat']),
			array('value'=>$order['dest_seat']),
		);
		if(!$url){
			$url=custom_url('jy_daijia/order/detail//id='.$order['id'],true);
		}
		cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'nopay2buyer','jy_daijia',$order['id']);
		if($_SESSION['wxapp_id']){
			$template_id=cfc('wxapp_api')->checktplNotice($order['mid'],$wxapptemplate_id,$wxappmsg,$url,'nopay2buyer','jy_daijia',$order['id']);
		}
	}
}
